#!/bin/bash

function backup_homes_to_usb() {
    homes_directory=$1

    usb_directory=$2

    echo "Checking for homes directory..."
    if [ ! -d "${homes_directory}" ]; then
        echo "No homes directory ${homes_directory} found. Exiting."
        exit 1
    fi


    echo "Checking for USB directory..."
    if [ ! -d "${usb_directory}" ]; then
        echo "No USB directory ${usb_directory} found. Exiting."
        exit 1
    fi



    echo "Backing up home directories to USB drive..."
    sudo rsync -av --exclude='@eaDir' --exclude='#recycle'  ${homes_directory}/* ${usb_directory}/
    echo "Backup completed."
}

 backup_homes_to_usb /volume2/homes /volumeUSB1/usbshare1-5/NAS_BACKUP  |tee  /tmp/backup_homes_to_usb.log

##curl -k https://gitee.com/team_space/mynet_info/raw/master/backup_homes_to_usb.sh|bash